/*!\brief
 *  Header file correcponding to the database connector.
 * @author Mazzer Yannis, Calingarayar Martial
 */
#ifndef _DBCONNECTOR_H
#define _DBCONNECTOR_H

#include <QObject>
#include <QtSql>
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QListWidgetItem>

enum paramPos{ DBNAME = 0,
       HOST = 1,
       USER = 2,
       DRIVER = 3,
       PORT = 4
	    };

/*
QT_BEGIN_NAMESPACE
class QSql;
QT_END_NAMESPACE
*/

/*!
 * The dbConnector class represent a database, it is the connection between
 * the program and the database.
 */
class dbConnector: public QListWidgetItem
{
public:

/*!
 * The default dbConnector class constructor.
 */
	dbConnector();

/*!
 * This function allows the integration of the parameters in the class to
 * initialize the connection. it returns the SQL error if the connection
 * failed
 * @param driver the type of the database
 * @param dbName the name of the database
 * @param host this is the host name
 * @param user user to access the database
 * @param passwd the password for the user
 * @param nick the nickName which will be used for the db
 * @param comment the comment
 * @param port the connection port
 * @return QSqlError error returned by the database
 */
	QSqlError addConnection(const QString &driver,
			const QString &dbName,
			const QString &host,
			const QString &user,
			const QString &passwd,
			const QString &nick,
			const QString &comment,
			int port);

/*!
 * This function initializes a model to store the results of a select query
 * on the Films table of the database.
 * @return QSqlTableModel a pointer to the model containing the results.
 */
	QSqlTableModel  *retrieveMovies();

/*!
 * This function initializes a model to store the results of a select query
 * on the Albums table of the database.
 * @return QSqlTableModel a pointer to the model containing the results
 */
	QSqlTableModel  *retrieveAlbums();

/*!
 * This function is an accessor to the database nickname.
 * @return QString the nickname
 */
	QString getNickName();

/*!
 * This function is an accessor to the database port.
 * @return int the port
 */
	int getPort();

/*!
 * This function is an accessor to the database hostname.
 * @return QString the hostname
 */
	QString getHost();

/*!
 * This function is an accessor to set the database nickname.
 * @param nickName the nick which will be set in place of the current one.
 */
	void setNickName(QString nickName);

/*!
 * This function is an accessor to set the database comment.
 * @param comment the comment which will be set in place of the current one.
 */
	void setComment(QString comment);

private:
	QSqlDatabase db;
	QSqlError err;
	QString driver;
	QString dbName;
	QString host;
	QString user;
	QString password;
	int port;
	QString nickName;
	QString comment;




};


#endif
